package com.kkd.kkdapp.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

public class PolygonView extends View {
	Paint mPaint = null;
	private int backgroundColor;
	private String text = "定期宝";
	private int oneX = 0;
	private int oneY = 0;
	private int twoX = 158;
	private int twoY = 0;
	private int threeX = 158;
	private int threeY = 60;
	private int fourX = 79;
	private int fourY = 90;
	private int fiveX = 0;
	private int fiveY = 60;
	private float size = 33;
	private int textX = 33;
	private int textY = 50;

	public PolygonView(Context context) {
		super(context);
		mPaint = new Paint();
		mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
	}

	public PolygonView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		mPaint = new Paint();
		mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
	}

	public PolygonView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mPaint = new Paint();
		mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		// 设置画布颜色 也就是背景颜色
		// 绘制多边形
		mPaint.setColor(backgroundColor);
		Path path = new Path();
		path.moveTo(oneX, oneY);
		path.lineTo(oneX + twoX, oneY + twoY);
		path.lineTo(oneX + threeX, oneY + threeY);
		path.lineTo(oneX + fourX, oneY + fourY);
		path.lineTo(oneX + fiveX, oneY + fiveY);
		path.close();
		canvas.drawPath(path, mPaint);
		mPaint.setColor(Color.WHITE);
		mPaint.setTextSize(size);
		canvas.drawText(text, 0 + textX, 0 + textY, mPaint);
	}

	public void setBackground(int backgroundColor) {
		this.backgroundColor = backgroundColor;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setXY(int oneX, int oneY, int twoX, int twoY, int threeX,
			int threeY, int fourX, int fourY, int fiveX, int fiveY) {
		this.oneX = oneX;
		this.oneY = oneY;
		this.twoX = twoX;
		this.twoY = twoY;
		this.threeX = threeX;
		this.threeY = threeY;
		this.fourX = fourX;
		this.fourY = fourY;
		this.fiveX = fiveX;
		this.fiveY = fiveY;
	}

	public void setTextSize(float size) {
		this.size = size;
	}

	public void setTextXY(int textX, int textY) {
		this.textX = textX;
		this.textY = textY;
	}
}
